﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_AdminSendMessage_SendMesToAdmin : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PopulateDrp();
        }
    }
    public void PopulateDate()
    {
        lvDate.DataSource = AdminUser.GetAllByConditon(DongDong.Common.Misc.ConvertToInt(drpUserType.SelectedValue), txtTimeFrom.Text, txtTimeTO.Text, txtUserName.Text);
        lvDate.DataBind();
    }

    public void PopulateDrp()
    {
        drpUserType.DataSource = AdminRole.GetAll();
        drpUserType.DataTextField = "RoleName";
        drpUserType.DataValueField = "ID";
        drpUserType.DataBind();
        drpUserType.Items.Insert(0, new ListItem("请选择", "0"));
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        PopulateDate();

    }

    protected void Pager_PreRender(object sender, EventArgs e)
    {
        if (lvDate.Items.Count == 0)
            PopulateDate();
    }
    protected void lvDate_PagePropertiesChanged(object sender, EventArgs e)
    {
        PopulateDate();
    }
    protected void bntSendZNX_Click(object sender, EventArgs e)
    {
        List<ZNXX> lstZNXX = new List<ZNXX>();
        //循环外面声明 提高性能
        ZNXX obj;
        //循环外面获取session里面的用户信息 提高性能
        int AdminUserID = AdminUser.GetCurrent().ID;
        //循环外面进行拆箱装箱操作 提高性能
        int Status = (int)ZNXX.statusXX.未读;
        int Type = (int)ZNXX.ZXXXType.前台;
        string Mess = txtMessage.Text;
        if (string.IsNullOrEmpty(Mess))
        {
            DongDong.Common.MessageBox.Show(this, "请输入发送内容");
            return;
        }
        else if (Mess.Length > 500)
        {
            DongDong.Common.MessageBox.Show(this, "发送内容太长");
            return;
        }
        Mess=LTP.Common.PageValidate.InputText(Mess, 500);

        foreach (ListViewDataItem item in lvDate.Items)
        {
            CheckBox cbCheckBox = (CheckBox)item.FindControl("cbCheckBox");
            if (cbCheckBox.Checked)
            {
                HiddenField hdlUserID = (HiddenField)item.FindControl("hdlUserID");
                obj = new ZNXX();
                obj.Des = Mess;
                obj.GetUserID = DongDong.Common.Misc.ConvertToInt(hdlUserID.Value);
                obj.Enable_Flag = 1;
                obj.SendTime = System.DateTime.Now;
                obj.SendUserID = AdminUserID;
                obj.Status = Status;
                obj.Type = Type;
                lstZNXX.Add(obj);
            }
        }
        if (lstZNXX.Count != 0)
        {
            ZNXX.AddAll(lstZNXX);
            DongDong.Common.MessageBox.ShowAndRedirect(this, "发送成功", "SendMesToClient.aspx");
        }
        else
        {
            DongDong.Common.MessageBox.Show(this, "请选择用户");
        }
    }
}